﻿using AutoMapper;
using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Image;
using MediatR;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Image
{
    public class QueryImageHandler : IRequestHandler<QueryImageCommand, ApiResult<List<Picture>>>
    {
        private readonly IBaseRepository<Picture> piRep;
        private readonly IMapper mapper;

        public QueryImageHandler(IBaseRepository<Picture> piRep, IMapper mapper)
        {
            this.piRep = piRep;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<Picture>>> Handle(QueryImageCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Picture>> result = new ApiResult<List<Picture>>();
            var list = piRep.GetAll().Where(x => x.ProductId == request.ProductId && !x.IsDel);
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
